package com.example;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import javax.jms.*;

@RunWith(SpringRunner.class)
@ContextConfiguration(locations = "classpath:spring-context2.xml")
public class SpringJmsTest2 {

    @Autowired
    private JmsTemplate jmsTemplate;
    @Autowired
    private Queue destinationQueue;
    @Autowired
    private Topic destinationTopic;

    @Test
    public void testSendToQueue() throws JMSException {
        jmsTemplate.send((Destination) destinationQueue, new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage("世界，你好！");
            }
        });
    }
}
